import static org.junit.Assert.*;


import org.junit.Before;
import org.junit.Test;

public class JUnitTestClientCommDummy {

	private ClientCommDummy cliComm;
	private ServerCommDummy serComm;
	private Order or_buy;
	private Order or_sell;

	@Before
	public void setUp() throws Exception {
		cliComm = new ClientCommDummy();
		serComm = new ServerCommDummy();
	}

	@Test
	public void test() {
		serComm.start();
		cliComm.connect(null, "Reinaldo");
		try {
			Thread.sleep(500);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		or_buy = createBuyOrder("Reinaldo", "Google", 50, 15);
		clientComm.sendOrder(or_buy);
		assertTrue(serComm.getMapaClients().containsKey("Reinaldo"));
		assertNotNull(cliComm.getNextMessage());

		or_sell = createSellOrder("Joana", "Google", 30, 15);
		ServerMessage sermes = new ServerMessage(Type.NEW_ORDER,or_sell,"Joana");
		cliComm.getSendMessageList().add(sermes);
		assertTrue(cliComm.isConnected());
		assertFalse(cliComm.hasNextMessage());

		cliComm.disconnect();
		try {
			Thread.sleep(500);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		assertFalse(clientComm.isConnected());
	}
}
